from flask_script import Manager
from flask_migrate import Migrate,MigrateCommand
from config import *
from info import db,create_app
from info.models import User

#-*- coding: UTF-8 -*
app=create_app(DevelopmentConfig)


manager=Manager(app)

Migrate(app, db)

manager.add_command('db',MigrateCommand)

# app.secret_key = 'itheima'



# logging.debug("This is a debug log.")
# logging.info("This is a info log.")
# logging.warning("This is a warning log.")
# logging.error("This is a error log.")
# logging.critical("This is a critical log.")


@manager.option('-p','-password',dest='password')
@manager.option('-n','-name',dest='name')
def createsuperuser(name,password):
    #先校验参数
    if not all([password,name]):
        print('参数不全')
        return

    user=User()
    user.password=password
    user.nick_name=name
    user.mobile=name
    user.is_admin=True
    try:
        db.session.add(user)
        db.session.commit()
        print('添加成功')
    except Exception as e:
        db.session.rollback()
        print(e)
        print('添加失败')

        return


if __name__ == '__main__':
    print(app.url_map)
    manager.run()



